package com.kube.numtostring;

import java.util.ArrayList;
import java.util.List;

public class NumToString {

		public static String getString(String num) {
		int j = num.length();
		List<String> decomposing = new ArrayList<String>();
		String decomposed="";
		int control=0;
		
		for (int i=0; i<j; i++) {			
		String digit=num.substring(i,i+1);
        System.out.println(digit);
        System.out.println(j-1-i);
		switch (j-1-i) {
		
		case 0:
			
			if (control==1) { decomposing.add(i,""); break; }
			if (digit.equals("1")) { decomposing.add(i,"one"); break; }
			if (digit.equals("2")) { decomposing.add(i,"two"); break; }
			if (digit.equals("3")) { decomposing.add(i,"three"); break; }
			if (digit.equals("4")) { decomposing.add(i,"four"); break; }
			if (digit.equals("5")) { decomposing.add(i,"five"); break; }
			if (digit.equals("6")) { decomposing.add(i,"six"); break; }
			if (digit.equals("7")) { decomposing.add(i,"seven"); break; }
			if (digit.equals("8")) { decomposing.add(i,"eight"); break; }
			if (digit.equals("9")) { decomposing.add(i,"nine"); break; }
			if (digit.equals("0")) { decomposing.add(i,"zero"); break; }
			
		case 1:
		
			if (digit.equals("1")) {
				
				if (num.substring(j-1,j).equals("1")) {decomposing.add(i,"eleven"); control=1; break; }
				if (num.substring(j).equals("2")) {decomposing.add(i,"twelve"); control=1; break; }
				if (num.substring(j).equals("3")) {decomposing.add(i,"thirteen"); control=1; break; }
				if (num.substring(j).equals("4")) {decomposing.add(i,"fourteen"); control=1; break; }
				if (num.substring(j).equals("5")) {decomposing.add(i,"fifteen"); control=1; break; }
				if (num.substring(j).equals("6")) {decomposing.add(i,"sixteen"); control=1; break; }
				if (num.substring(j).equals("7")) {decomposing.add(i,"seventeen"); control=1; break; }
				if (num.substring(j).equals("8")) {decomposing.add(i,"eighteen"); control=1; break; }
				if (num.substring(j).equals("9")) {decomposing.add(i,"nineteen"); control=1; break; }
				if (num.substring(j-1,j).equals("0")) {System.out.println("here");decomposing.add(i,"ten"); control=1; break; }
			
			}
			
			if (digit.equals("2")) { decomposing.add(i,"twenty "); break; }
			if (digit.equals("3")) { decomposing.add(i,"thirty "); break; }
			if (digit.equals("4")) { decomposing.add(i,"forty "); break; }
			if (digit.equals("5")) { decomposing.add(i,"fifty "); break; }
			if (digit.equals("6")) { decomposing.add(i,"sixty "); break; }
			if (digit.equals("7")) { decomposing.add(i,"seventy "); break; }
			if (digit.equals("8")) { decomposing.add(i,"eighty "); break; }
			if (digit.equals("9")) { decomposing.add(i,"ninety "); break; }
			if (digit.equals("0")) { decomposing.add(i,""); break; }
			
		case 2:
			
			if (digit.equals("1")) { decomposing.add(i,"one hundred and "); break; }
			if (digit.equals("2")) { decomposing.add(i,"two hundreds and "); break; }
			if (digit.equals("3")) { decomposing.add(i,"three hundreds and "); break; }
			if (digit.equals("4")) { decomposing.add(i,"four hundreds and "); break; }
			if (digit.equals("5")) { decomposing.add(i,"five hundreds and "); break; }
			if (digit.equals("6")) { decomposing.add(i,"six hundreds and "); break; }
			if (digit.equals("7")) { decomposing.add(i,"seven hundreds and "); break; }
			if (digit.equals("8")) { decomposing.add(i,"eight hundreds and "); break; }
			if (digit.equals("9")) { decomposing.add(i,"nine hundreds and "); break; }
			if (digit.equals("0")) { decomposing.add(i,"and "); break; }
			
		case 3:
			
			if (digit.equals("1")) { decomposing.add(i,"one thousand "); break; }
			if (digit.equals("2")) { decomposing.add(i,"two thousands "); break; }
			if (digit.equals("3")) { decomposing.add(i,"three thousands "); break; }
			if (digit.equals("4")) { decomposing.add(i,"four thousands "); break; }
			if (digit.equals("5")) { decomposing.add(i,"five thousands "); break; }
			if (digit.equals("6")) { decomposing.add(i,"six thousands "); break; }
			if (digit.equals("7")) { decomposing.add(i,"seven thousands "); break; }
			if (digit.equals("8")) { decomposing.add(i,"eight thousands "); break; }
			if (digit.equals("9")) { decomposing.add(i,"nine thousands "); break; }
			
		
		}
		
		decomposed=decomposed+decomposing.get(i);
		System.out.println("The number "+num+" is written "+decomposed);
		
		}
	
	return decomposed;
  }	

}